Problem Challenge 3

Smallest Window containing Substring (hard) #

Given a string and a pattern, find the smallest substring in the given string which has all the characters of the given pattern.

Example 1:

Input: String="aabdec", Pattern="abc"
Output: "abdec"
Explanation: The smallest substring having all characters of the pattern is "abdec"

Example 2:

Input: String="abdabca", Pattern="abc"
Output: "abc"
Explanation: The smallest substring having all characters of the pattern is "abc".

Example 3:

Input: String="adcad", Pattern="abc"
Output: ""
Explanation: No substring in the given string has all characters of the pattern.

Try it yourself #

Try solving this question here:

1 of 3 Tests Passed
ResultInputExpected OutputActual OutputReason
findSubstring(aabdec, abc)abdecIncorrect Output
findSubstring(abdabca, abc)abcIncorrect Output
findSubstring(adcad, abc)Succeeded
3.392s
Mark as Completed
←    Back
Solution Review: Problem Challenge 2
Next    →
Solution Review: Problem Challenge 3